const SERVICE = require("../../lib/js/service.js");

Page({
  data:{
    // SearchVal:"VF1VYRTY9DC459034",
    SearchVal: "",
    num: 0,
    imgSrc: SERVICE.imgUrl,
    word:0,
    showNavItem: 0,
  },
  onLoad(){
   
  },

  onShow(){
    this.getOrderNum();
  },

  /**
   * @explain 获取用户报价清单数量
   * @params thirdCookie 用户信息
   * 
   * **/
  getOrderNum() {
    let _this = this;
    SERVICE.POST(SERVICE.URL.getCart, {
      thirdCookie: wx.getStorageSync("thirdCookie")
    }, (status, res) => {
      if(res.data.status === "success"){
        _this.setData({
          num: res.data.count
        });
      }else{
        wx.showToast({
          title: "获取信息失败",
          icon: "none",
          mask: true
        });
      }
    });
  },
  
  /*分享*/
  onShareAppMessage(){},
  SearchSubmit(e){
    if(e.detail.value.search.length == 0){
      wx.showToast({
        title: "请输入VIN码",
        icon: "none",
        mask: true
      });
    } else if (e.detail.value.search.length < 17){
      wx.showToast({
        title: "请输入完整的VIN码",
        icon: "none",
        mask: true
      });
    }else{
      wx.navigateTo({
        url: "../vehicle-model/vehicle-model?search_val=" + e.detail.value.search
      });
    }
  },

  searchInput(e){
    let td = this.data, val = e.detail.value;
    let val_2 = "";
    for (let i of val) {
      if (!/[\u4e00-\u9fa5]/.test(i)) {
        val_2 += i;
      }
    }
    if (val.length > 0){
      this.setData({
        SearchVal: val_2.toUpperCase(),
        word: val_2.length
      });
    }else{
      this.setData({
        word: 0
      });
    }
  },
  searchInput2(e) {
    let td = this.data, val = e.detail.value;
    let val_2 = "";
    for (let i of val) {
      if (!/[\u4e00-\u9fa5]/.test(i)) {
        val_2 += i;
      }
    }
    this.setData({
      SearchVal2: val_2.toUpperCase(),
      word2: val_2.length
    });
  },
  SearchSubmit2(e) {
    let search_val = e.detail.value.search;
    if (search_val.length > 0) {
      wx.navigateTo({
        url: "../mountings-list/mountings-list?search_val=" + search_val
      });
    }
  },

  getNavItem(e){
    let showNavItem = e.currentTarget.dataset.index;
    this.setData({
      showNavItem
    });  
  },
  clear(e){
    this.setData({
      word: 0,
      SearchVal: ""
    });
  },
  clear2(){
    this.setData({
      SearchVal2: "",
      word2: 0
    });
  }
});